home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / jnos110g.zip / TIP.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  3KB  |  134 lines

  1. /* "Dumb terminal" session command for serial lines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *      Feb '91 Bill Simpson
  5.  *              rlsd control and improved dialer
  6.  */
  7. /* mods by PA0GRI */
  8. #include "global.h"
  9. #include "mbuf.h"
  10. #include "proc.h"
  11. #include "iface.h"
  12. #ifndef UNIX
  13. #include "i8250.h"
  14. #endif
  15. #ifdef LINUX
  16. #include "lxasy.h"
  17. #endif
  18. #include "asy.h"
  19. #include "tty.h"
  20. #include "session.h"
  21. #include "socket.h"
  22. #include "commands.h"
  23. #include "devparam.h"
  24.   
  25.   
  26. static void tip_out __ARGS((int dev,void *n1,void *n2));
  27.   
  28.   
  29. /* Execute user telnet command */
  30. int
  31. dotip(argc,argv,p)
  32. int argc;
  33. char *argv[];
  34. void *p;
  35. {
  36.     struct session *sp;
  37.     register struct iface *ifp;
  38.     struct asy *ap;
  39.     char *ifn;
  40.     int (*rawsave) __ARGS((struct iface *,struct mbuf *));
  41.     int c;
  42.   
  43.     /*Make sure this comes from console - WG7J*/
  44.     if(Curproc->input != Command->input)
  45.         return 0;
  46.   
  47.     if((ifp = if_lookup(argv[1])) == NULLIF){
  48.         tprintf(Badinterface,argv[1]);
  49.         return 1;
  50.     }
  51.     ap=&Asy[ifp->dev];
  52.     if( ifp->dev >= ASY_MAX || ap->iface != ifp ){
  53.         tprintf("Interface %s not asy port\n",argv[1]);
  54.         return 1;
  55.     }
  56.     if(ifp->raw == bitbucket){
  57.         tprintf("tip or dialer session already active on %s\n",argv[1]);
  58.         return 1;
  59.     }
  60.   
  61.     /* Allocate a session descriptor */
  62.     if((sp = newsession(argv[1],TIP,0)) == NULLSESSION){
  63.         tputs(TooManySessions);
  64.         return 1;
  65.     }
  66.   
  67.     /* Save output handler and temporarily redirect output to null */
  68.     rawsave = ifp->raw;
  69.     ifp->raw = bitbucket;
  70.   
  71.     /* Suspend the packet input driver. Note that the transmit driver
  72.      * is left running since we use it to send buffers to the line.
  73.      */
  74.     suspend(ifp->rxproc);
  75. #ifdef POLLEDKISS
  76.     suspend(ap->poller);
  77. #endif
  78.   
  79.     /* Put tty into raw mode */
  80.     sp->ttystate.echo = 0;
  81.     sp->ttystate.edit = 0;
  82.     sockmode(sp->output,SOCK_BINARY);
  83.   
  84.     /* Now fork into two paths, one rx, one tx */
  85.     ifn = if_name( ifp, " tip out" );
  86.     sp->proc1 = newproc(ifn,256,tip_out,ifp->dev,NULL,NULL,0);
  87.     free( ifn );
  88.   
  89.     ifn = if_name( ifp, " tip in" );
  90.     chname( Curproc, ifn );
  91.     free( ifn );
  92.   
  93.     /* bring the line up (just in case) */
  94.     if ( ifp->ioctl != NULL )
  95.         (*ifp->ioctl)( ifp, PARAM_UP, TRUE, 0L );
  96.   
  97.     while((c = get_asy(ifp->dev)) != -1)
  98.         tputc(c & 0x7f);
  99.     tflush();
  100.   
  101.     killproc(sp->proc1);
  102.     sp->proc1 = NULLPROC;
  103.     ifp->raw = rawsave;
  104.     resume(ifp->rxproc);
  105. #ifdef POLLEDKISS
  106.     resume(ap->poller);
  107. #endif
  108.     keywait(NULLCHAR,1);
  109.     freesession(sp);
  110.     return 0;
  111. }
  112.   
  113.   
  114. /* Output process, DTE version */
  115. static void
  116. tip_out(dev,n1,n2)
  117. int dev;
  118. void *n1,*n2;
  119. {
  120.     struct mbuf *bp;
  121.     int c;
  122.   
  123.     while((c = recvchar(Curproc->input)) != EOF){
  124.         if(c == '\n')
  125.             c = '\r';               /* NL => CR */
  126.         bp = pushdown(NULLBUF,1);
  127.         bp->data[0] = (c & 0x7f);
  128.         asy_send(dev,bp);
  129.         Asy[dev].iface->lastsent = secclock();
  130.     }
  131. }
  132.   
  133.   
  134.